import pygame

from pygame.sprite import Sprite

class Buttel(Sprite):
    """飞船子弹的管理类"""

    def __init__(self, ai_settings, screen, ship):
        super(Buttel,self).__init__()
        self.screen = screen

        #在（0,0）处创建一个表示子弹的矩形，并设置正确位置
        self.rect = pygame.Rect(0,0,ai_settings.bullet_width, ai_settings.bullet_height)
        self.rect.centerx = ship.rect.centerx
        self.rect.top = ship.rect.top

        self.y = float(self.rect.y)

        self.color = ai_settings.bullet_color
        self.speed = ai_settings.bullet_speed_factor

    def update(self):
        """向上移动子弹"""
        self.y -= self.speed
        self.rect.y = self.y

    def draw_bullet(self):
        """在屏幕上绘制子弹"""
        pygame.draw.rect(self.screen, self.color ,self.rect)

